package com.yyh.synctool.server.test;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.util.Scanner;

/**
 * @author xuan
 * @date 2021/12/2
 */
public class Send
{
    public static final String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("223.247.213.71");
        factory.setUsername("admin");
        factory.setPassword("!qazHYEYLISEN");
        // 开启5672端口

        Scanner input = new Scanner(System.in);

        try(Connection connection = factory.newConnection();
            Channel channel = connection.createChannel()) {
            channel.queueDeclare(QUEUE_NAME, false, false, false, null);

            System.out.print("请输入你要发送的消息：");
            while (input.hasNextLine()) {
                String message = input.nextLine();
                channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
                System.out.println("[生产者] Send \""+message+"\"\n");
                System.out.print("请输入你要发送的消息：");
            }
        }
    }
    /**
     * 1.create a connection to the server
     * 2.connect to a RabbitMQ node on the local machine  --> specify hostname or ip address to connect different machine
     * 3.create a channel
     */
}
